export function Login({
	appId,
	redirect_url
}) {
	//获取url上的code
	var url = document.location.toString();
	var result = {
		code: '',
	};
	if (url.indexOf('?') != -1) {
		let luyIindex = url.indexOf('#');
		let tiHuanIndex = url.indexOf('?')
		let luyou = url.slice(luyIindex);
		let tihuan = url.slice(tiHuanIndex, luyIindex);
		url = url.split("?");
		url = url[0];
		url = url + luyou + tihuan;
		var arrobj = url.split('?');
		if (arrobj.length) {
			//取出所有传的值
			var arrPara = arrobj[1].split("&");
			var arr = [];
			for (var i = 0; i < arrPara.length; i++) {
				arr = arrPara[i].split("=");
				//把第二个值赋值给第一个值
				result[arr[0]] = arr[1];
			}
		}
	}
	if (result.code) {
		console.log(result.code,'result.code')
		return result.code
	} else {
		let empowerUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=" +
			encodeURIComponent(redirect_url) + "&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
		window.location.href = empowerUrl
	}
}
